var member_id = ws = spage = travel_id = '';
document.addEventListener('plusready',function(){
	member_id = plus.storage.getItem('id');
	ws = plus.webview.currentWebview();
	spage = ws.spage;
	travel_id = ws.travel_id;
	$.ajax({
		type:"post",
		url:apiRoot + "?act=member_travel&op=travel_one",
		data:{
			member_id:member_id,
			travel_id:travel_id
		},
		dataType:'json',
		success:function(data){
			console.log(JSON.stringify(data));
			if(data.code == 200){
				$('.travel_name').val(data.datas.travel_name);
				$('.travel_phone').val(data.datas.travel_phone);
				(data.datas.travel_type == '成人')?$("input[name='radio']").eq(0).attr('checked','checked'):$("input[name='radio']").eq(1).attr('checked','checked');
				(data.datas.travel_sex == '男')?$("input[name='radio1']").eq(0).attr('checked','checked'):$("input[name='radio1']").eq(1).attr('checked','checked');
				$('.travel_idnumber').val(data.datas.travel_idnumber);
			}else{
				toast(data.datas.error);
			}
		},
		error:function(e){
			error();
			
		}
	});
	
	//编辑完成
	$('.complete').on('click',function(){ 
		var travel_name = $('.travel_name').val();
		var travel_phone = $('.travel_phone').val();
		var travel_type = $("input[name='radio']:checked").val();
		var travel_sex = $("input[name='radio1']:checked").val();
		var travel_idnumber = $('.travel_idnumber').val();
		if(!travel_name){ 
			toast('姓名不能为空!');return;
		}
		if(travel_phone){
			if(!travel_phone.match(p1)){ 
				toast('请输入正确的联系电话!');return;
			}
		}
		if(travel_idnumber){
			if(!travel_idnumber.match(isIDCard1)){
				toast('请输入正确格式的身份证号码!');return;
			}
		}
//		console.log(travel_name+'---'+travel_phone+'---'+travel_type+'---'+travel_sex+'---'+travel_idnumber);return;
		plus.nativeUI.showWaiting('保存中...');
		$.ajax({
			type:"post",
			url:apiRoot + "?act=member_travel&op=travel_upl",
			data:{
				travel_id:travel_id,
				member_id:member_id,
				travel_name:travel_name,
				travel_phone:travel_phone,
				travel_type:travel_type,
				travel_sex:travel_sex,
				travel_idnumber:travel_idnumber
			},
			dataType:'json',
			success:function(data){
				console.log(JSON.stringify(data));
				plus.nativeUI.closeWaiting();
				if(data.code == 200){
					toast('修改成功！');
					plus.webview.getWebviewById(spage).reload();
					setTimeout(function(){
						ws.close();
					},500)
				}else{
					toast(data.datas.error);
				}
			},
			error:function(e){
				plus.nativeUI.closeWaiting();
				error();
			}
		});
	})
})
